package 链表;

public class deleteDuplicates {

    public ListNode deleteDuplicates(ListNode head) {
        if(head==null) return head;
        ListNode p=head,q=head.next;
        while (q!=null){
            while (p!=null && q!=null && p.val==q.val){
                q=q.next;
            }

            p.next=q;
            p=q;
            if(q!=null) q=q.next;
        }
        return head;
    }
}
